<template>
 <div class="myContainer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="20" class="myLineHeight_40px">
        <span v-if="type=='add'">新增</span>
        <span v-if="type=='update'">编辑</span>        
      </el-col>
    </el-row>
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        店铺名称 :
      </el-col>
      <el-col :span="7">
       <el-input v-model="STORENAME" placeholder="请输入店铺名称" :readonly="is_modifly"></el-input>
      </el-col>
    </el-row>
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        店铺联系人 :
      </el-col>
      <el-col :span="7">
        <el-input v-model="CONTACTER" placeholder="请输入联系人名称" :readonly="is_modifly"></el-input>
      </el-col>
    </el-row>
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        联系人电话 :
      </el-col>
      <el-col :span="7">
        <el-input v-model="TEL" placeholder="请输入电话" :readonly="is_modifly"></el-input>
      </el-col>
    </el-row>
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        标语 :
      </el-col>
      <el-col :span="7">
       <el-input v-model="SLOGAN" placeholder="请输入标语" :readonly="is_modifly"></el-input>
      </el-col>
    </el-row>
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        省 :
      </el-col>
      <el-col :span="7">
        <el-select v-model="PROVINCE"
          @change="changeDistrictSelect"
          :disabled="is_disabled"
          placeholder="请选择省">
          <el-option
            v-for="item in province"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        市 :
      </el-col>
      <el-col :span="7">
        <el-select v-model="CITY"
         @change="changeAreaSelect"
         :disabled="is_disabled"
          placeholder="请选择市">
          <el-option
            v-for="item in areaList"
            :key="item.AREA_ID"
            :label="item.AREANAME"
            :value="item.AREA_ID">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        区县 :
      </el-col>
      <el-col :span="7">
        <el-select v-model="DISTRICT"
          :disabled="is_disabled"
          placeholder="请选择县">
          <el-option
            v-for="item in buildingList"
            :key="item.AREA_ID"
            :label="item.AREANAME"
            :value="item.AREA_ID">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        所属小区 :
      </el-col>
      <el-col :span="7">
       <el-input v-model="VILLAGEID" placeholder="请输入所属小区" :readonly="is_modifly"></el-input>
      </el-col>
    </el-row>

    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        店铺地址 :
      </el-col>
      <el-col :span="7">
       <el-input v-model="ADDRESS" placeholder="请输入店铺地址" :readonly="is_modifly"></el-input>
      </el-col>
    </el-row>
    
    <!-- <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        删除标记 :
      </el-col>
      <el-col :span="7">
       <template>
          <el-select 
            v-model="DELETED"
            clearable
            placeholder="请选择刪除标志">
            <el-option
              v-for="item in deleteSignList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
    </el-row> -->
    
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="10" :offset="3">
        <el-button v-if="type=='add'" @click="create" class="myBgGreen">新 增</el-button>
        <el-button v-if="type=='update' && isShow(157)" @click="modify" class="myBgGreen">保 存</el-button>
        <el-button @click="onBack" class="myBgGreen">返 回</el-button>
      </el-col>
    </el-row>
    
  </div>
</template>

</template>

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
  .myVA_M{
    vertical-align: middle;
  }     
    .focusNone{width: 1000px;margin: 0 auto;}
    input.form-control,.bs-select.form-control{width: 100%;}
    @media (max-width: 768px){
      .cz{margin-bottom: 0px;}
      .dataTotal{top: -5px;}
      .bs-select{width: 60%;}
    }
     .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
<script>
  import { getCommerceDetail,createCommerce,province,options,modifyCommerce , getCityList } from '@/api/commerce';
  import qs from "querystring";
  export default {
    data(){
      return{
        title:"超市店铺管理",
        id: null,
        detail: {},

        type:'',
        is_modifly:true,
        is_disabled:false,
        
        areaList: [],
        buildingList:[],
               
        building_id:-1,
        selectedLd:-1,

        STORETYPE:"1",
        CONTACTER:"",
        TEL:"",
        SLOGAN:"",
        STORENAME:"",
        ADDRESS:"",
        USER_ID:"",

        building_id:-1,
        selectedLd:"-1",
        xqdlist:[
          
        ],
        
        province:province,
        options:options,
        
        PROVINCE:"",
        CITY:"",
        DISTRICT:"",
        VILLAGEID:"",
        DELETED:"",
        deleteSignList:[{value:0,label:"未删除"},{value:1,label:"已删除"}],
      }
    },
    
    components: {    	
    },
    
    created(){
      var vm = this;
      vm.type = vm.$route.query.type;
      vm.id = vm.$route.query.id;
      if(vm.type=='update'){ //修改
        vm.is_modifly = false;
        vm.fetchDetail();
      }
      if(vm.type=='add'){
        vm.is_modifly = false;
      }
    },
    
    methods:{       
    //---------详情数据 	
      fetchDetail() {
        let vm = this;
        getCommerceDetail(vm.id)
            .then(response => {
          let res = response.data.OBJECT;                 
          vm.CONTACTER=res.CONTACTER;
          vm.TEL=res.TEL;
          vm.SLOGAN=res.SLOGAN;
          vm.STORENAME=res.STORENAME;
          vm.ADDRESS=res.ADDRESS;
          vm.PROVINCE=res.PROVINCE+"";
          vm.CITY=res.CITY+"";
          vm.DISTRICT=res.DISTRICT+"";
          vm.VILLAGEID=res.VILLAGEID;
          //vm.DELETED=res.DELETED;
          vm.onGetCityList(vm.PROVINCE);
          vm.onGetCountyList(vm.CITY);
        })
        .catch(error => {
        })
      },
          
//---保存-
    modify:function(){
        let vm = this;
        let params={
          STORE_ID:vm.id,
          STORETYPE:vm.STORETYPE,
          STORENAME:vm.STORENAME,
          CONTACTER:vm.CONTACTER,
          TEL:vm.TEL,
          SLOGAN:vm.SLOGAN,
          PROVINCE:vm.PROVINCE,
          CITY:vm.CITY,
          DISTRICT:vm.DISTRICT,
          VILLAGEID:vm.VILLAGEID,
          ADDRESS:vm.ADDRESS,
          //DELETED:vm.DELETED
        }
        modifyCommerce(qs.stringify(params))
        .then(response => {    
          vm.$message.success("执行成功！"); 
          vm.$router.go(-1);        
        })
        .catch(error=> {
          vm.$message.error("执行失败！");
        });
      },
 
 //---新增---
    create:function(){                  
        let vm = this;
        let params={
          STORETYPE:vm.STORETYPE,
          STORENAME:vm.STORENAME,
          CONTACTER:vm.CONTACTER,
          TEL:vm.TEL,
          SLOGAN:vm.SLOGAN,
          PROVINCE:vm.PROVINCE,
          CITY:vm.CITY,
          DISTRICT:vm.DISTRICT,
          VILLAGEID:vm.VILLAGEID,
          ADDRESS:vm.ADDRESS,
          //DELETED:vm.DELETED
        }
        createCommerce(qs.stringify(params))
        .then(response => {
          vm.$message.success("执行成功！");
          vm.$router.go(-1);         
        })
        .catch(error=> {
          vm.$message.error("执行失败！");
        });
     },
     
     onBack(){
        this.$router.go(-1);
     },
     
     changeDistrictSelect(val){//拉取市
       this.CITY="";
       this.DISTRICT="";
       this.onGetCityList(val);
     },
     
     changeAreaSelect(val){//拉取区县
       this.DISTRICT="";
       this.onGetCountyList(val);
     },
     
     onGetCityList(val){//拉取市
       let vm=this;
       let params={
        PARENTAREAID:val
       }
       getCityList(qs.stringify(params)).then(response => {
          let res=response.data;
          vm.areaList=res.OBJECT;
          console.log(res)
       }).catch(error => {
          console.log(error)
       })
     },
     
     onGetCountyList(val){//拉取区县
       let vm=this;
       let params={
        PARENTAREAID:val
       }
       getCityList(qs.stringify(params)).then(response => {
          let res=response.data;
          vm.buildingList=res.OBJECT;
          console.log(res)
       }).catch(error => {
          console.log(error)
       })
     }

  }
 }


</script>



